<%-- 
    Document   : index
    Created on : Mar 24, 2011, 6:05:11 PM
    Author     : Reza
--%>


<%@page import="com.restfb.types.Group"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="objectRank.QueryGraph"%>
<%@page import="objectRank.Node"%>
<%@page import="com.restfb.*"%>
<%@page import="my.facebook.GraphExample"%>
<%@page import="com.google.code.facebookapi.FacebookJaxbRestClient"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Personalized web search in social network</title>
	<script src="http://www.google.com/jsapi"></script>
        <script language="Javascript" type="text/javascript" src="jquery-1.5.2.min.js"></script>
    </head>

    <script language="Javascript" type="text/javascript">

        //<![CDATA[
        // This Global variable is used to reference the MyGSearch object.
        var myGSearch;
        var query;
        var doc;
        var docClicked = false;
        
        // A helper object which wraps some of the Google Search API.
        function MyGSearch() {
            this.SearchControl = null;
            // Initializes all of the properties and google.search object.
            this.Initialize = function () {
            // Create the "search form"
                this.SearchControl = new google.search.SearchControl();
                // Bind the searchComplete and searchStarting methods
                this.SearchControl.setSearchCompleteCallback(this, this.onSearchComplete);
                // Set up the search result display options
                this.SearchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
                this.SearchControl.setLinkTarget(google.search.Search.LINK_TARGET_BLANK);
                // Create the Google Searcher
                var searcher = new google.search.WebSearch();
                // now add the "searcher" to the google search control
                this.SearchControl.addSearcher(searcher);
                // Assign some drawoptions to the searchcontrol
                var drawOptions = new google.search.DrawOptions();
                drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
                // Draw the control
                this.SearchControl.draw(document.getElementById('web-contents'), drawOptions);
            }

            // This event is raised by the google.search component. In it we will show the SearchResults.
            this.onSearchComplete = function (searchControl, searcher) {
                if (searcher.results.length ==0){document.getElementById('web-content').innerHTML = "Your search did not match any documents!";return;}
                var cursor = searcher.cursor;
                // Number of search result pages
                var pageCount = cursor.pages.length;
                // The current search result page
                var currentPage = cursor.currentPageIndex;
                // DIV to keep the results
                var contentDiv = document.getElementById('web-content');
                contentDiv.innerHTML = '';
                if(!searcher.allResults|| currentPage==0){searcher.allResults = [];}
                var results = searcher.results;
                searcher.allResults = searcher.allResults.concat(results);
                if (cursor && pageCount>currentPage+1){ searcher.gotoPage(currentPage+1); }
                var newResultsDiv = document.createElement('div');
                newResultsDiv.id = 'web-content';
                var href1 = "http://localhost:8080/MyGroups/DocumentServlet?query=" + query;
                for (var i = 0; i < searcher.allResults.length; i++) {
                    var result = searcher.allResults[i];
                    doc = result.unescapedUrl;
                    //var resultHTML = '<div>';
                    //resultHTML += '<a href="' + doc + '" target="_blank"' +
			//		'onclick="return clickReport();"><b>' +
			//		result.titleNoFormatting + '</b></a><br/>' +
			//		result.content +
			//		'<div/>';
                    //newResultsDiv.innerHTML += resultHTML;
                    href1 += "&document=" + doc + "&title=" + result.titleNoFormatting;
                }
                window.open(href1, "myFrame1");
                window.open("http://localhost:8080/MyGroups/ProcessServlet?query=" + query, "myFrame");
                //contentDiv.appendChild(newResultsDiv);

            }
        }
        
        // Initializes the myGSearch variable. Sets all of the properties that
        // are required for the google search to work.
        function InitializeMyGSearch() {
            myGSearch = new MyGSearch();
            // Initial the myGSearch object
            myGSearch.Initialize();
        }

        // Helper function to call the execute method.  It uses the
        // google search objects input field for the searching.
        function Search() {
            query = document.getElementById("query").value;
            var href1 = "http://localhost:8080/MyGroups/QueryServlet?query=" + query;
            window.open(href1, "myFrame");
            myGSearch.SearchControl.execute(query);
        }

        function clickReport(){
            //docCLicked = true;
            // ******* send the (query, URL, clicked) for the server *******
            var href1 = "http://localhost:8080/MyGroups/ClickServlet?query=" + query +
                               "&document=" + doc;
            window.open(href1, "mfFrame");
            //window.open(href1, "myFrame", "width=0,height=0");
            //docClicked = false;
            return true;
        }

        function pausecomp(millis){
            var date = new Date();
            var curDate = null;
            do { curDate = new Date(); }
            while(curDate-date < millis);
        }


        // Loads all of the Google Search APIs
        google.load('search', '1');
        // Call a google helper function which will call
        // InitializeMyGSearch on the Windows.OnLoad event for the browser.
        google.setOnLoadCallback(InitializeMyGSearch);


        //]]>
    </script>
    
    
    <body onload="document.getElementById('query').focus()">
	Personalized Google Web Search<br />
        
        <div>
            <input type="text" size=40 id="query" name="query" onkeydown="if (event.keyCode == 13) document.getElementById('search').click();"/>
            <input type="button" value="Search" id="search" onClick="Search();" method="POST"/>
	</div>
	
        <div class="data" id="web-content"></div>
        
        <iframe name="myFrame" width="500" height="500" onClick="alert(); return true;"></iframe>
        <iframe name="myFrame1" width="0" height="0"></iframe>
    </body>
    
</html>
